<?php
class FieldPath
{
	static $pathSeparator = "-";
	
	public function getPathString($arrFields)
	{
		return implode(self::$pathSeparator, $arrFields);
	}
	
	/**
	 * Resolves an $obj value from $path. Path is a id string (generated from rip), where
	 * format is (startObjectEDOid-)relation-relation..-..-fieldName.
	 *
	 * @param EDO_Object_basic $obj Startobject
	 * @param string $path Path to value
	 * @return The value
	 */
	public function resolve($obj, $path, $pathSeparator = null)
	{
		if(!$pathSeparator)
		{
			$pathSeparator = self::$pathSeparator;
		}
		
		
		
		$pathArr = explode($pathSeparator, $path);
		/*
		$startObj = array_shift($pathArr);
		
		$value = NULL;
		
		if($obj->getClass() == $startObj)
		{
				
		}*/
		
		$ptrRelation = $obj;
		
		while (count($pathArr)>1)
		{
			$relationName = array_shift($pathArr);
			$oldRelation = clone($ptrRelation);
			$ptrRelation = $ptrRelation->getField($relationName);
			if(!is_object($ptrRelation))
			{
				#return null;
			    	throw new Exception('Path could not be resolved, broken path');
			}
			
		}
		
		$varName = array_shift($pathArr);
		
		$value = $ptrRelation->getField($varName);
	
		
		return $value;	
	}
}
